<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>底部导航</title>
    <link rel="stylesheet" type="text/css" href="../../css/api1.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style1.css"/>
    <link rel="stylesheet" type="text/css" href="QA_style.css"/>
</head>
<body>
<div id="wrap" class="">

    <div id="main" class="question_info">
      <div class="fixed_top">
      <header id="header" class="header-box">
        <div class="left" onclick="back()"></div>
        <div class="center"></div>
        <div class="right" onclick="little_window()"></div>
      </header>
      </div>
      <div id='little-window' class="little-window" style="display:none">
        <ul>
          <li>取消悬赏</li>
          <li>分享</li>
          <li>举报</li>
        </ul>
      </div>
      <div id = "title" class="title"tapmode  onclick="closelitwindow()">
      </div>
      <div id="tag"  class="tag"tapmode  onclick="closelitwindow()">
         ·  ·
      </div>

      <div class="follow-box">
          <div >
              <div id="reward-num" class="reward-logo">
                  悬赏0元
              </div>
          </div>
      </div>

      <div id="description" class="description"  onclick="closelitwindow()">
          wjeoafpiejfpaweijfpefjipefjasdifjaidsifjsdikfjaefio;awmndnsvnodcz;
          ijviafeaio;fdsfj;aeifcksdvcd;lzkdvzmc;lzkvc;;a
      </div>
       <div class="show_all" onclick="showQ()">展开问题描述∨</div>

      <div style="width: 100%;height: 50px; ">
          <div style="width: 33%;float: left;text-align: center;margin-top: 10px;font-size: medium;border-right: 1px solid grey;" onclick="approveQ()">同问</div>
          <div style="width: 33%;float: left;text-align: center;margin-top: 10px;font-size: medium" onclick="yaoqing()">@大佬</div>
          <div style="width: 33%;float: left;text-align: center;margin-top: 10px;font-size: medium;border-left: 1px solid grey;" onclick="openAnswerQ()">帮TA</div>
      </div>


    </div>


    <div id="answer" class="answer" onclick="closelitwindow()">

    </div>

</div>
</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.js"></script>
<script type="text/javascript" src="../../script/dropload.min.js"></script>
<script type="text/javascript">
    var qs_data = {};
    var as_data = {};
    var qs_dict;
    var as_dict;

var qs_id ;
    apiready = function () {


        var main = $api.byId('header');
        var title = $api.byId('title');
        var tag = $api.byId('tag');
        var footer = $api.byId('footer');

        var header_H = $api.offset(header).h;
        var tag_H = $api.offset(tag).h;
        var title_H = $api.offset(title).h;
        qs_id = api.pageParam.question_id;
        qs_dict = {
            "app_version":"",
            "user_id":"e3b3dc8d20b7052f5c0799f3aa4e9f3e",
            "user_cookie":"fd2066e452fa3d60130e227412e51051",
            "type":"homework",
            "question_id": qs_id
        }
        as_dict = {
            "app_version":"",
            "user_id":"e3b3dc8d20b7052f5c0799f3aa4e9f3e",
            "user_cookie":"fd2066e452fa3d60130e227412e51051",
            "type":"homework",
            "question_id":qs_id,
            "since_id": 0,
            "page_size": 10
        }
        GetQuestion(qs_dict);
        question_view();
        GetAnswer(as_dict)
    }
    function approveQ() {
        var data ={
            "app_version":"",
            "user_id":"e3b3dc8d20b7052f5c0799f3aa4e9f3e",
            "user_cookie":"fd2066e452fa3d60130e227412e51051",
            "type":"homework",//"homework","normal"
            "question_id": qs_id
        };
        $.ajax({
            type: 'POST',
            // url: "http://1.82.238.228:80/api/questionAnswer/getQuestion/",
            url: "http://1.82.238.228:80/api/questionAnswer/concernQuestion/",
            data:JSON.stringify(data),
            // crossDomain: true,
            dataType: 'json',
            async: false,
            success:function(result){
                console.log('问题加载成功')
                alert('点赞成功')
                // view_tips(result)
            },
            error:function(error){
                alert(JSON.stringify(error));
            }
        });

    }

    function GetQuestion(json) {
        $.ajax({
            type: 'POST',
            // url: "http://1.82.238.228:80/api/questionAnswer/getQuestion/",
            url: "http://1.82.238.228:80/api/questionAnswer/getQuestion/",
            data:JSON.stringify(json),
            // crossDomain: true,
            dataType: 'json',
            async: false,
            success:function(result){
                console.log('问题加载成功')
                qs_data =  result
                alert(JSON.stringify(qs_data))
                // view_tips(result)
            },
            error:function(error){
                alert(JSON.stringify(error));
            }
        });
    }

    function GetAnswer(json) {
        $.ajax({
            type: 'POST',
            // url: "http://1.82.238.228:80/api/questionAnswer/getAnswer/",
            url: "http://1.82.238.228:80/api/questionAnswer/getAnswer/",
            data:JSON.stringify(json),
            // crossDomain: true,
            dataType: 'json',
            async: false,
            success:function(result){

                as_data =  result.data;
                alert(JSON.stringify(as_data))
                answer_view();
                // view_tips(result)
            },
            error:function(){
                console.log('回答列表加载失败');
            }
        });
    }

    function question_view() {
        document.getElementById('title').innerHTML = qs_data.title;
        var tag_content = '';

        for ( var i = 0; i<3; i++) {
            if (i == 0) {
                tag_content = tag_content + qs_data.tag[i];
            }
            else {
                tag_content = tag_content + ' · ' + qs_data.tag[i];
            }
        }
        document.getElementById('tag').innerHTML = tag_content;
        document.getElementById('description').innerHTML = qs_data.detail;
        document.getElementById('reward-num').innerText = '悬赏'+qs_data.reward+'元';
        //document.getElementById('answer_content').childNodes[1].innerHTML = json_data.answer_content;
        if (qs_data.is_concered == true) {
            change_follow()
        }
    }

    function answer_view() {
        tmp = document.getElementById('answer');
        for (var i = 0; i < parseInt(as_data.length); i++) {
            parentNode = document.getElementById('answer')
            sourceNode = document.createElement('span');
            sourceNode.setAttribute('id','answer-'+i);
            sourceNode.setAttribute('class','answer-box');
            parentNode.appendChild(sourceNode);
            childNode1 = document.createElement('div');
            childNode1.setAttribute('class','answer-box-left');
            sourceNode.appendChild(childNode1);
            grandNode = document.createElement('div');
            grandNode.setAttribute('class','answer-user-imag');
            childNode1.appendChild(grandNode);
            imgNode = document.createElement('img');
            imgNode.src = "http://1.82.238.228/file"+as_data.img_list[i];
            grandNode.appendChild(imgNode);

            childNode2 = document.createElement('div');
            childNode2.setAttribute('class','answer-box-right');
            sourceNode.appendChild(childNode2);
            grandNode1 = document.createElement('div');
            interNode1 = document.createElement('div');
            interNode1.setAttribute('class','approve-logo');
            interNode1.innerHTML = as_data[i].like_num;
            sourceNode.appendChild(interNode1);
            grandNode1.setAttribute('class','answer-user-name');
            grandNode1.innerHTML = '用户名' + i;
            childNode2.appendChild(grandNode1);
            grandNode2 = document.createElement('div');
            grandNode2.setAttribute('class','answer-user-comment');
            grandNode2.innerHTML = as_data[i].content;
            childNode2.appendChild(grandNode2);
            grandNode3 = document.createElement('div');
            grandNode3.setAttribute('class','interactive-box');
            childNode2.appendChild(grandNode3);

        }
        for (var j=0; j<as_data.length; j++) {
            tmp = document.getElementById('answer-'+j);
            tmp1 = as_data[j].answer_id;
            tmp2 = as_data[j].question_id;
            $(tmp.childNodes[1].childNodes[1]).attr('onclick','open_answer_detail('+tmp1+','+tmp2+')')
        }

    }

    function showQ() {
        var node = document.getElementById('description');
        node.setAttribute('class','descriptionShow');
    }

    function openAnswerQ(){
        api.openWin({
            name:'open_Answer_question',
            url:'edit_answer_win.html'
        })
    }

    var litwindow = $api.dom('#little-window');

    function little_window() {
        if (litwindow.style.display == "none") {
            litwindow.style.display = 'block';
        }
        else {
            litwindow.style.display = 'none';
        }
    }


    function closelitwindow() {
        litwindow.style.display = 'none';
    }
    function open_comment() {
        api.openFrame({
            name: 'comment',
            url: './comment_box.html',
            rect: {
                x:0,
                y:0,
                w:api.winWidth,
                h:api.winHeight
            },
            pageParam: {
                question_id: 1,
                answer_id: 1,
                user_id: 'e3b3dc8d20b7052f5c0799f3aa4e9f3e',
                type:"question"
            },
            bgColor: 'rgba(0,0,0,0.6)',
            // bounces: false,
        });
    }
    function change_follow() {
        var flag;
        if (document.getElementById('follow_logo').innerHTML == '+关注') {
            flag = 1; //表示关注动作
            document.getElementById('follow_logo').innerHTML = '取消关注';
            $.ajax({
                type: 'POST',
                // url: "http://1.82.238.228:80/api/questionAnswer/concernQuestion/",
                url: "http://1.82.238.228:80/api/questionAnswer/concernQuestion/",
                data:JSON.stringify(qs_dict),
                dataType: 'json',
                async: false,
                success:function(result){
                    console.log('关注成功')
                    tmp =  result.message
                    console.log(tmp)
                },
                error:function(){
                    console.log('关注失败');
                }
            });
        }
        else {
            flag = 0; //表示取消关注动作
            document.getElementById('follow_logo').innerHTML = '+关注';
            $.ajax({
                type: 'POST',
                url: "http://1.82.238.228:80/api/questionAnswer/deleteQuestion/",
                data:JSON.stringify(qs_dict),
                dataType: 'json',
                async: false,
                success:function(result){
                    console.log('取关成功')
                    tmp =  result.message
                },
                error:function(){
                    console.log('取关失败');
                }
            });
        }

    }

    function open_answer_detail(as_id,qs_id) {
        api.openWin({
            name: 'hobby_question_detail',
            url: './hobby_question_detail.html',
            pageParam: {
                question_id: qs_id,
                answer_id: as_id
            }
        });
    }

    function edit_answer() {
        api.openWin({
            name: 'edit_answer',
            url: './edit_answer_win.html',
            pageParam: {
                question_id: api.pageParam.question_id
            }
        });

    }

    function yaoqing() {
        closelitwindow();
        api.openWin({
            name: 'invite_win',
            url: './invite_win.html',
            pageParam: {
                name: 'test'
            }
        })
    }

    function jubao() {
        closelitwindow();

        alert('举报成功!')
    }




    function back() {
        api.openWin({
            name: 'viewby_cata_hobby',
            url: './viewby_cata_hobby.html',
            pageParam: {
                name: 'test'
            }
        });
    }


</script>
